/*
 * PluginName : modalBox
 * @author:Carlos O Carvalho
 * 
 */
(function($$, window, document, undefined) {

    $$.fn.modalBox = function(options) {
        var $ele = this,
                $o = $$.extend({}, {
                    data: '<h2>Modal box</h2>',
                    title: 'Modal',
                    id: 'iModalBox',
                    callbackBeforeRender: function(e,$obj) {

                    },
                    callbackAfterRender: function($obj) {

                    }
                    
                }, options || {});
        var modalHtml = '<div class="modal fade iModalBox" id="' + $o.id + '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'
                + '<div class="modal-dialog">'
                + '<div class="modal-content">'
                + '<div class="modal-header">'
                + '<h4 class="imodal-title">' + $o.title + '</h4>'
                + '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'
                + '</div>'
                + '<div class="modal-body">'
                + $o.data
                + ' </div>'

                + ' </div>'
                + ' </div>'
                + '</div>';

        $$($ele).bind('click', function(e) {
        	$('.iModalBox').remove();
        	var $obj = $(modalHtml).appendTo('body');
        	$o.callbackBeforeRender(e, $obj);
            e.preventDefault();
            $('.iModalBox').modal();
            $o.callbackAfterRender($obj);

        });
         
        
        
            

    };
    
    
    
    $.fn.onCloseModalBox = function(){
    	$('.iModalBox [data-dismiss="modal"]').trigger('click');
    }

})(jQuery, window);